import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/provider/record_provider.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';

/**
 * auth sunjichao
 * desc:录音授权
 */
class AuthorizationRecord extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return AuthorizationRecordState();
  }
}

class AuthorizationRecordState extends State<AuthorizationRecord> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('录音授权'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                child: Text(
                  "授权平台收集和听取行程录音",
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: ScreenUtil().setSp(48)),
                ),
                padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
              ),
              Container(
                child: Text(
                  "授权后才可以使用录音保护功能",
                ),
                padding: EdgeInsets.only(left: 10),
              ),
              Container(
                child: Text(
                  "* 录音只在本设备完成，将使用你的流量",
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: ScreenUtil().setSp(36)),
                ),
                padding: EdgeInsets.only(left: 10, top: 20),
              ),
              Container(
                child: Text(
                  "授权后，每次行程进行中你使用此功能都将调起设备麦克风。受设备性能限制，车内环境较差或 者网络信号不好时，可能会导致无法录音或者部 分录音听不清楚。",
                  style: TextStyle(fontSize: ScreenUtil().setSp(32)),
                ),
                padding: EdgeInsets.only(left: 10, top: 2),
              ),
              Container(
                child: Text(
                  "* 保障纠纷取证，调查判责清晰",
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: ScreenUtil().setSp(36)),
                ),
                padding: EdgeInsets.only(left: 10, top: 20),
              ),
              Container(
                child: Text(
                  "平台不会实时监测行程录音，录音仅用于产生投诉纠纷时的调查取证，以录音为依据，更易明确责任方。",
                  style: TextStyle(fontSize: ScreenUtil().setSp(32)),
                ),
                padding: EdgeInsets.only(left: 10, top: 2),
              ),
              Container(
                child: Text(
                  "* 录音加密保存，保护你和对方的隐私",
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: ScreenUtil().setSp(36)),
                ),
                padding: EdgeInsets.only(left: 10, top: 20),
              ),
              Container(
                child: Text(
                  "麦田将按照相关的法律规定，加密录音信息，保护你和对方的隐私。如无行程纠纷录音记录将于7天后自动删除",
                  style: TextStyle(fontSize: ScreenUtil().setSp(32)),
                ),
                padding: EdgeInsets.only(left: 10, top: 2),
              ),
              Container(
                padding: EdgeInsets.only(
                    left: ScreenUtil().setWidth(20),
                    top: ScreenUtil().setWidth(10)),
                child: RichText(
                  text: TextSpan(
                      text: "你可以查看",
                      style: TextStyle(color: Colors.black),
                      children: [
                        TextSpan(
                          text: "《录音收集信息协议》",
                          style: TextStyle(
                            color: Colors.deepOrange,
                          ),
                          recognizer: TapGestureRecognizer()
                            ..onTap = () {
                              NavigatorUtil.jump(context, '/agreementRecoid');
                            },
                        ),
                      ]),
                ),
              )
            ],
          ),
          Container(
            padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
            child: RaisedButton(
              onPressed: () {
                PermissionHandler().requestPermissions(
                    [PermissionGroup.storage, PermissionGroup.speech]);
                Provider.of<RecordProvider>(context, listen: false)
                    .startRecord();
                NavigatorUtil.goBack(context);
              },
              child: Text("同意并授权"),
              textColor: Colors.white,
              color: Color.fromARGB(255, 78, 79, 95),
            ),
          )
        ],
      ),
    );
  }
}
